package com.mew.chess.core.game.qmcs.game.common;

import cn.hutool.core.util.RandomUtil;
import com.zebra.common.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import lombok.*;

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class QmcsBO {

    private int fishId;
    private int fishType;  // 鱼类型ID
    private int ruleStep;     // 规定步长
    private int remainStep;   // 剩余步长；
    private long startTime;
    private int routeId;         // 路线
    //private byte rollback;  //0 正序  1 反序


    public int getRemainStep(){
        //单位帧
        if (0 == this.startTime){
            this.startTime = System.currentTimeMillis();
            return 0;
        }

        return QmcsTableUtil.computeRemainStep(this.startTime);
    }


    public static QmcsBO creat(int fishId, QmcsRoute qmcsRoute){
        QmcsBO qmcsBO = new QmcsBO();
        qmcsBO.fishId = fishId;
        qmcsBO.routeId = qmcsRoute.getLineID();
        qmcsBO.ruleStep = qmcsRoute.getRootLength();
        qmcsBO.startTime = System.currentTimeMillis();
        qmcsBO.fishType = qmcsRoute.getFishType()[RandomUtil.randomInt(qmcsRoute.getFishType().length)];

        return qmcsBO;
    }

    public static QmcsBO creat(int fishId, int fishType){
        QmcsBO qmcsBO = new QmcsBO();
        qmcsBO.fishId = fishId;
        qmcsBO.routeId = 0;
        qmcsBO.ruleStep = QmcsConstantValue.FISH_TIDE_CYCLE;
        qmcsBO.startTime = System.currentTimeMillis();
        qmcsBO.fishType = fishType;

        return qmcsBO;
    }

    public void write(ByteBuf b){
        ByteBufUtils.writeInt(b,fishId);
        ByteBufUtils.writeInt(b,fishType);
        ByteBufUtils.writeInt(b,getRemainStep());
        ByteBufUtils.writeInt(b,routeId);
    }

    public static void main(String[] args) {
        long startTime = 1625033886642l;

        long diff = System.currentTimeMillis() -  startTime;


        long step = 25000 / QmcsConstantValue.STEP_TIME;

        System.out.println(1195* QmcsConstantValue.STEP_TIME);
        System.out.println(diff);
        System.out.println(step);
    }

}
